############################################################
# Define what graphics files we have as input and as output.
#

TOOLS_FOLDER = tools

PNG_INPUTS = $(wildcard *.png)
FIG_INPUTS = $(wildcard *.fig)
DIA_INPUTS = $(wildcard *.dia)
EPS_INPUTS = $(FIG_INPUTS:.fig=.eps) $(PNG_INPUTS:.png=.eps) \
	       $(DIA_INPUTS:.dia=.eps) 

EPS_OUTPUTS = $(EPS_INPUTS)
PDF_OUTPUTS = $(EPS_INPUTS:.eps=.pdf)

JPG_OUTPUTS = $(EPS_ALL:.eps=.jpg)
PPT_OUTPUTS = $(EPS_ALL:.eps=.ppt.eps)

# Make sure we know how to remove the garbage.
RM = rm -f
GARBAGE = $(EPS_OUTPUTS) $(JPG_OUTPUTS) $(EPS_ALL) *.pdf

pdf: $(PDF_OUTPUTS) 

ps: $(EPS_OUTPUTS)

export: $(EPS_OUTPUTS) $(JPG_OUTPUTS)

powerpoint: $(EPS_OUTPUTS) $(PPT_OUTPUTS)

######################################################################
# Don't forget to tell make how to convert the graphics into something
# usable.

%.ppt.eps: %.eps
	cp $< $@
	$(TOOLS_FOLDER)/make_palette $@


#%.eps:	%.pdf
#	$(RM) $(<:.pdf=.ps)
#	pdf2ps $<
#	ps2eps --ignoreBB $(<:.pdf=.ps)



%.jpg: %.eps
	convert -density 300x300 $< $@

# Construct an implicit rule for conversion of fig into eps.
%.eps: %.fig
	$(TOOLS_FOLDER)/fig2eps -f -d0 -p$(TOOLS_FOLDER)/fig2eps -pamsmath -pamsfonts -pamsthm $<

#fig2dev -L eps $< $@

%.eps: %.dia
	dia --nosplash -e $@ $<

# Tell how to use convert for getting png images into more usefull eps files.
%.eps: %.png
	convert -colors 240 -compress rle $< eps:$@

# Last but not least, for pdflatex we need to have the eps converted to pdf.
%.pdf: %.eps
	epstopdf $< -o $@


########################################################
# Tell make how to clean up the temporary graphic files.
#
# Clean up created files.
clean:
	$(RM) $(GARBAGE)

.PHONY: ps export clean powerpoint
